//
//  NSObject+Defulat.m
//  lTTheOne
//
//  Created by AA on 2024/1/28.
//

#import "NSObject+Defulat.h"
#import "BGFMDB.h"
#import "HeaderConfig.h"

@implementation NSObject (Defulat)

+ (void)afterTime:(CGFloat)time Block:(void (^)(void))block {
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(time * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
      if (block) {
          block();
      }
    });
}

+ (void)userISLogin:(NSString *)islogin {
    defalut
        [userDefalut setObject:islogin
                        forKey:UserISLogin];
    [userDefalut synchronize];
}

+ (BOOL)userIsISLogin {
    defalut
        BOOL isSave = [userDefalut objectForKey:UserISLogin];
    return isSave;
}

+ (NSString *)userGetISLogin {
    defalut if ([[userDefalut objectForKey:UserISLogin] isKindOfClass:[NSDictionary class]]) {
        return @"";
    }
    NSString *token = [userDefalut objectForKey:UserISLogin] == nil ? @"" : [userDefalut objectForKey:UserISLogin];
    return token;
}

+ (void)clearISLogin {
    defalut
        [userDefalut removeObjectForKey:UserISLogin];
    [NSObject bg_clear:UserInfo];

    // 修改 clearISLogin 方法
    Class userManagerClass = NSClassFromString(@"MSUserManager");
    if (userManagerClass) {
        SEL sharedManagerSelector = NSSelectorFromString(@"sharedManager");
        if ([userManagerClass respondsToSelector:sharedManagerSelector]) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
            id userManager = [userManagerClass performSelector:sharedManagerSelector];
#pragma clang diagnostic pop
            SEL clearAllModelSelector = NSSelectorFromString(@"clearAllModel");
            if ([userManager respondsToSelector:clearAllModelSelector]) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
                [userManager performSelector:clearAllModelSelector];
#pragma clang diagnostic pop
            }
        }
    }
}

@end
